package com.swpu.eduorder.controller;
import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.swpu.commonutils.JwtUtils;
import com.swpu.commonutils.R;
import com.swpu.eduorder.entity.TOrder;
import com.swpu.eduorder.service.TOrderService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;
import javax.servlet.http.HttpServletRequest;

/**
 * 订单 前端控制器
 * @author ygq
 * @since 2021-10-30
 */
@RestController
@CrossOrigin
@RequestMapping("/eduorder/order")
public class TOrderController {
    @Autowired
    private TOrderService orderService;

    @PostMapping("createOrder/{courseId}")
    public R save(@PathVariable String courseId, HttpServletRequest request){
        System.out.println("进入方法");
        String orderId = orderService.saveOrder(courseId, JwtUtils.getMemberIdByJwtToken(request));
        System.out.println(orderId);
        return R.ok().data("orderId", orderId);
    }
    @GetMapping("getOrder/{orderId}")
    public R get(@PathVariable String orderId) {
        QueryWrapper<TOrder> wrapper = new QueryWrapper<>();
        wrapper.eq("order_no",orderId);
        TOrder order = orderService.getOne(wrapper);
        return R.ok().data("item", order);
    }


}

